package com.xinchao.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.xinchao.core.BaseController;
import com.xinchao.core.constant.ResponseConstant;
import com.xinchao.model.sys.JsonResponse;
import com.xinchao.model.vo.DeviceWarnLogVO;
import com.xinchao.service.DeviceWarnLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 终端报警日志
 *
 * @author linqiang
 * @date 2018-08-09 15:46
 */
@Controller
@RequestMapping(value = "/deviceWarnLog")
public class DeviceWarnLogController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(DeviceWarnLogController.class);
    @Autowired
    private DeviceWarnLogService deviceWarnLogService;

    /**
     * 终端报警日志分页列表
     *
     * @param pageNum  当前页
     * @param pageSize 每页条数
     * @param request  请求
     * @return Object
     */
    @ResponseBody
    @RequestMapping(value = "/listByPage")
    public Object listByPage(Integer pageNum, Integer pageSize, HttpServletRequest request) {
        try {
            String currentCity = getCurrentCityName(request);
            Page<DeviceWarnLogVO> page = deviceWarnLogService.listByPage(currentCity, pageNum, pageSize);
            PageInfo<DeviceWarnLogVO> pageInfo = new PageInfo<>(page);
            return new JsonResponse(ResponseConstant.CODE_SUCCESS, pageInfo, "获取终端报警日志列表成功");
        } catch (Exception e) {
            logger.error("DeviceWarnLogController listByPage 获取终端报警日志列表失败：" + e.getMessage());
        }
        return new JsonResponse(ResponseConstant.CODE_FAIL, "获取终端报警日志列表失败");
    }
}
